import java.util.Random;
import java.util.Scanner;

public class Array {

    public static void main(String[] args) {
        dArray();
    }

    //    1. 生成10个随机数(0,100)进入数组
//    2. 得出最大值
//    3. 计算平均数，多少个数小于平均数，它们分别是
    public static void randArray() {
        Scanner sc = new Scanner(System.in);
        Random r = new Random();
        int[] arr = new int[10];
        int max = arr[0];
        int total = 0;
        for (int i = 0; i < 10; i++) {
            arr[i] = r.nextInt(100);
            total += arr[i];
            if (arr[i] > max) {
                max = arr[i];
            }
        }
        int average = total / 10;
        int count = 0;
        int[] arr2 = new int[5];
        int j = 0;
        for (int i = 0; i < 10; i++) {
            if (arr[i] < average) {
                count++;
                arr2[j++] = arr[i];
            }
        }
        System.out.println("10位整型随机数的数组最大值是:" + max + " 平均数为:" + average + " 小于平均数的数的个数有" + count + "个");
        System.out.println("它们分别是:");
        for (int i = 0; i < arr2.length; i++) {
            System.out.print(arr2[i] + " ");
        }
    }

    //   动态初始化
    public static void Array01() {
        int[] arr = new int[10];
        arr[0] = 5;
        for (int i = 0; i < arr.length; i++) {
            System.out.println("第" + (i + 1) + "个数是:" + arr[i] + " ");
        }
    }

    //    遍历数组
    public static void Array02(int[] arr) {
        System.out.print("[");
        for (int i = 0; i < arr.length; i++) {
            if (i == arr.length - 1) {
                System.out.print(arr[i]);
                break;
            }
            System.out.print(arr[i] + ", ");
        }
        System.out.print("]");
    }

    //    复制数组
    public static void Array03(int[] arr, int from, int to) {
        if (from > to || from < 0 || to >= arr.length) {
            System.out.println("输入不合法...remake");
            return;
        }
        int[] arr2 = new int[to - from + 1];
        int j = 0;
        for (int i = from; i < to + 1; i++) {
            arr2[j] = arr[i];
            j++;
        }
        System.out.println("已复制，新的数组为:");
        Array02(arr2);
    }

    //    删除指定下标数组
    public static void Array04() {
        Sb[] sbs = {
                new Sb("sb", 20),
                new Sb("jwz", 15),
                new Sb("fw", 20),
        };
        System.out.println("删除前:");
        for (Sb sb : sbs) {
            if (sb != null)
                System.out.println(sb.getName() + " " + sb.getAge() + " " + sbs.length);
        }
        int x = 2;
        sbs[x] = null;
        System.out.println("删除后:");
        for (Sb sb : sbs) {
            if (sb != null)
                System.out.println(sb.getName() + " " + sb.getAge() + " " + sbs.length);
        }
    }

    //二维数组
    public static void dArray() {
        int[][] arr = new int[4][4];
        for (int i = 0; i < 4; i++) {
            for (int j = 0; j < 4; j++) {
                System.out.print(arr[i][j] + " ");
            }
            System.out.println();
        }
    }
}
